package com.example.test.启动线程.生产消费;


public class Produer implements Runnable {

    private Data data;

    public Produer(Data data) {
        this.data = data;
    }

    @Override
    public void run() {
        int i = 0;

        while (true) {
            synchronized (data) {
                if (null == data.getMessage()) {
                    System.out.println(Thread.currentThread().getName());
                    data.setMessage("生成消息"+i++);
                    System.out.println(data.getMessage());
                    data.notify();
                    try {
                        data.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }

    }
}
